package com.droidwatcher.variables;

import com.alibaba.fastjson.JSON;
import com.droidwatcher.JsonEntity.HttpRequestHead;
import com.droidwatcher.JsonEntity.RegAndLoginJsonObj;
import com.droidwatcher.JsonEntity.RegistAndLoginEntityInfo;
import com.droidwatcher.lib.MessageType;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/1/24.
 */

public class LoginServerMsg implements IServerMessage {
    public MessageType type;

    private Map<String, Object> map;

    @Override
    public MessageType getType() {
            return type;
    }

    public LoginServerMsg(MessageType type){
        this.type = type ;
        this.map = new HashMap<String, Object>();
    }

    public LoginServerMsg addParam(String key, Object value) {
        map.put(key, value);
        return this;
    }

    @Override
    public String getJSONString() {

        RegAndLoginJsonObj obj = new RegAndLoginJsonObj() ;
        obj.setHead(new HttpRequestHead());
        RegistAndLoginEntityInfo registInfo  = new RegistAndLoginEntityInfo();

        registInfo.setPassword((String) map.get("pwd"));
        registInfo.setUsername((String) map.get("login"));
        obj.setInfo(registInfo);

        return JSON.toJSONString(obj);

    }

//    public void getDataFromDH(final String parameters){
//
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    AXLog.e("wzytest","getDataFromDH  parameters:"+parameters);
//                    String apiURL = "http://sp.kuuvv.com/api/user/signup";
//                    HttpClient httpClient = new DefaultHttpClient();
//                    HttpPost post = new HttpPost(apiURL);
//                    post.addHeader("Content-type","application/json; charset=utf-8");
//                    post.setHeader("Accept", "application/json");
//                    try {
//                        post.setEntity(new StringEntity(parameters, "UTF-8"));
//                        HttpResponse response = httpClient.execute(post);
//                        int statusCode = response.getStatusLine().getStatusCode();
//                        if (statusCode != HttpStatus.SC_OK) {
//                            AXLog.e("wzytest" , "response.getStatusLine()" + response.getStatusLine());
//                        }
//                        String body = EntityUtils.toString(response.getEntity());
//
//                        AXLog.e("wzytest","getDataFromDH statusCode:"+statusCode +" body:"+body);
//                    } catch (UnsupportedEncodingException e) {
//                        e.printStackTrace();
//                    } catch (ClientProtocolException e) {
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//
//                }
//            }).start();
//    }

}
